package com.demo.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.servlet.ModelAndView;

import java.util.HashMap;
import java.util.Map;

@ControllerAdvice
public class GlobalHandlerException {

    // 只能处理自定义异常
    @ExceptionHandler(value = {CustomerException.class})
    public ModelAndView handlerCustomerException(CustomerException e) {
        System.out.println("======global=======");
        Map<String, Object> context = new HashMap<>();
        context.put("ex", e);
        return  new ModelAndView("cus_error", context);
    }

    // 只能处理系统异常
    @ExceptionHandler(value = {Exception.class})
    public ModelAndView handlerSystemException(Exception e) {
        Map<String, Object> context = new HashMap<>();
        context.put("ex", e);
        return  new ModelAndView("sys_error", context);
    }

}
